package com.zhongxia.controller;

import com.zhongxia.entity.User;
import com.zhongxia.entity.UserVO;
import com.zhongxia.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: 废柴弟弟
 * @Date: 2020/4/1 11:38
 */
@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private UserMapper userMapper;

    @GetMapping("findAll/{index}/{limit}")
    public UserVO findAll(@PathVariable("index") int index, @PathVariable("limit") int limit)
    {
        return new UserVO(0,"",userMapper.count(),userMapper.findAll(index, limit));
    }

    @PostMapping("/save")
    public void save(@RequestBody User user){

        userMapper.save(user);
    }

    @DeleteMapping("/deleteById/{id}")
    public void deleteById(@PathVariable("id") int id){
        userMapper.deleteById(id);
    }
    @GetMapping("count")
    public int count()
    {
        return userMapper.count();
    }
}
